#include "core/log.hpp"

FileLog::FileLog(const std::string& fname)
{
  f.open(fname);
}

FileLog::~FileLog()
{
  f.close();
}

void FileLog::writeOut(const std::string& m)
{
  f << m;
}

void TermLog::writeOut(const std::string& m)
{
  std::cerr << m;
}

MetaLog::MetaLog()
{
  if(isTesting)
    {
      flog = MKUPTR(FileLog, "./log_test.txt");
      tlog = MKUPTR(TermLog);
    }
  else
    {
      flog = MKUPTR(FileLog, "./log.txt");
      tlog = MKUPTR(TermLog);
      //glog = std::unique_ptr<GuiLog>(NULL);
    }
}

MetaLog::~MetaLog()
{
  if(flog)
    {
      flog.reset();
    }
  if(tlog)
    {
      tlog.reset();
    }
  //if(glog)
  //  {
  //    glog.reset();
  //  }
}

void MetaLog::writeOut(const std::string& m)
{
  flog.get() << m;
  tlog.get() << m;
  //if(glog)
  //  {
  //    glog << m;
  //  }
}
